<%@ page import="com.actimind.actitime.Keys,com.actimind.actitime.reports.*"%>
<%@ page errorPage="/error.jsp" %>
<%@ taglib uri="/WEB-INF/at.tld" prefix="at" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<at:CheckLoggedIn/>

<html>
<head>
    <title><bean:write name="title-prefix" scope="application"/> Prepare Invoice Data</title>
    <link rel="stylesheet" href="../css/at.css" type="text/css">
    <script language="JavaScript" src="../js/at.js"></script>
    <script language="JavaScript" src="../js/calendar.js?r=1"></script>

<script language="JavaScript">
function checkFields(f)
{
    if(getVal(f.customer) <= 0)
    {
        window.alert('Please select a customer');
        f.customer.focus();
        return false;
    }
    var projectSelected = false;
    for(var i = 0; i < f.projects.options.length; i++)
    {
        if(f.projects.options[i].selected)
            projectSelected = true;
    }
    if(!projectSelected)
    {
        window.alert('Please select at least one project');
        f.projects.focus();
        return false;
    }
    if(fromDate > toDate)
    {
        window.alert('"From" date should be before "To" date');
        return false;
    }
    return true;
}
</script>
</head>
<body bgcolor="#ffffff" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" onLoad="document.forms[0].autocomplete='off';">

<jsp:include page="../top.jsp" flush="false">
    <jsp:param name="pageSection" value="reports"/>
    <jsp:param name="pageAction" value="prepareinvoice"/>
</jsp:include>

<at:form action="/reports/prepareinvoice" method="post" onsubmit="return checkFields(this);">
<html:hidden property="pageAction" value=""/>
<html:hidden property="submitted" value="true"/>

<bean:define id="form" name="PrepareInvoiceForm" type="com.actimind.actitime.reports.PrepareInvoiceForm" />

<table width="770" align="center" cellspacing="0" cellpadding="4" border="0">
    <tr>
        <td class="pagetitle" valign="top">Prepare Invoice Data</td>
    </tr>
    <tr><td><at:errors/></td></tr>
</table>

<table width="770" align="center" cellspacing="0" cellpadding="4" border="0">
    <tr>
        <td class="textemphasis" colspan="2">Please note that invoice will 
            include only Billable tasks. All Non-Billable tasks will not
            be considered.
        </td>
    </tr>
    <tr>
        <td nowrap="1" width="48" class="formblocktitle">STEP 1.</td>
        <td class="formblocktitle">CHOOSE CUSTOMER TO INVOICE</td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td>
            <at:select property="customer" childSelect="projects" style="width: 180px" width="180" maxlength="35">
                <at:option value="-1">-- Select a customer --</at:option>
                <at:options collection="<%=Keys.CUSTOMERS_LIST_KEY%>" property="id" labelProperty="name"/>
            </at:select>
            <br>
            <span class="smallcomment">Only billable customers are shown.</span>
        </td>
    </tr>
    <tr>
        <td nowrap="1" class="formblocktitle">STEP 2.</td>
        <td><span class="formblocktitle" >CHOOSE INVOICE TYPE</span></td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td>
            <table cellspacing="0" cellpadding="0" border="0">
                <tr>
                    <td><html:radio property="rangeType" value='<%=""+BillingSummaryReportForm.TYPE_TIME_REPORTED%>' /></td>
                    <td class="text">Bill by time reported for a date range</td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td class="smallcomment">Invoice will include number of hours spent on the 
                        tasks (including incomplete tasks) within the specified date range.</td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td>
            <table cellspacing="0" cellpadding="0" border="0">
                <tr>
                    <td><html:radio property="rangeType" value='<%=""+BillingSummaryReportForm.TYPE_TIME_SPENT_ON_COMPLETED_TASKS%>' /></td>
                    <td class="text">Bill by time spent on tasks completed within a date range</td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td class="smallcomment">Invoice will include overall number of hours
                        (starting from task creation) spent on the tasks that were completed within
                        the specified date range.</td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td nowrap="1" class="formblocktitle" >STEP 3.</td>
        <td><span class="formblocktitle" >SPECIFY DATE RANGE</span></td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td><%@include file="date_utils.jsp"%></td>
    </tr>
    <tr>
        <td nowrap="1" class="formblocktitle" >STEP 4.</td>
        <td><span class="formblocktitle" >CHOOSE CUSTOMER PROJECTS TO INVOICE</span></td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td>
            <at:select multiple="true" property="projects" parentSelect="customer" style="width: 300px" size="6" width="180" maxlength="47">
                <at:options collection="<%=Keys.PROJECTS_LIST_KEY%>" property="id" parentProperty="customerId" labelProperty="name"/>
            </at:select>
            <br>
            <span class="smallcomment">Only billable projects are shown.</span>
        </td>
    </tr>
    <tr>
        <td nowrap="1" class="formblocktitle" >STEP 5.</td>
        <td><span class="formblocktitle" >CHOOSE LEVEL OF DETAILS AND GROUPING OPTIONS</span></td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td class="text"><html:radio property="invoiceType" value='<%=""+PrepareInvoiceForm.INVOICE_TASKS_GROUPED_BY_BILLING_TYPES%>' />Show tasks grouped by billing types</td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td class="text"><html:radio property="invoiceType" value='<%=""+PrepareInvoiceForm.INVOICE_PLAIN_LIST_OF_TASKS%>' />Show plain list of tasks</td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td class="text"><html:radio property="invoiceType" value='<%=""+PrepareInvoiceForm.INVOICE_PLAIN_LIST_OF_PROJECTS%>' />Hide tasks/show projects only</td>
    </tr>
    <tr>
        <td nowrap="1" bgcolor="#E5E5E5" class="formblocktitle">STEP 6.</td>
        <td class="text" align="center" bgcolor="#E5E5E5">
            <table cellspacing="0" cellpadding="2" border="0" width="100%">
            <tr>
                <td width="50%" align="right"><input type="submit" onclick="this.form.pageAction.value='html'; return true;" value="Preview in HTML/Export for Quickbooks"></td>
                <td class="text" align="center">-- OR --</td>
                <td width="40%" align="left"><input type="submit" onclick="this.form.action='<html:rewrite href='prepareinvoice.csv'/>'; this.form.pageAction.value='csv'; return true;" value="      Export to CSV      "></td>
            </tr>
            </table>
        </td>
    </tr>
</table>

<br>

</at:form>
</body>
</html>
